package com.lx.pattern.singleton;

/**
 *  双重校验单例模式
 *  比较完美的单例模式
 */
public class Singleton {
    private static volatile Singleton singleton;

    private Singleton(){

    }

    public static Singleton getSingleton(){
        if (null==singleton){
            synchronized (Object.class){
                if (null==singleton){
                    singleton= new Singleton();
                }
            }
        }
        return singleton;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(()-> System.out.println( Singleton.getSingleton().hashCode())).start();
        }
    }

    public void add(int a,int b){

    }
}
